<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYTCONN();
// SAVE TICKET
if (isset($_POST['SaveTicket'])) {
	$ref_type = $_POST['Area'];
	if($_POST['status'] == "3") {
		$StatusSolve = "refUserSolve = '{$_SESSION[$SESSID]}', time_solve = '{$sysTime}',";
	} else {
		$StatusSolve = "";
	}
	if($_POST['status'] == "5") {
		$timeClose = date("Y-m-d H:i:s");
	} else {
		$timeClose = "0000-00-00 00:00:00";
	}
	if($_POST['status'] == "4" && ($_POST['time_confirm'] != "" || $_POST['time_confirm'] != "0000-00-00 00:00:00")) {
		$timeConfirm = date("Y-m-d H:i:s");
	} else {
		$timeConfirm = "0000-00-00 00:00:00";
	}
	
	$USave = "UPDATE it_tickets SET
				ref_type = '{$ref_type}',
				timeClose = '{$timeClose}',
				Observations = '{$_POST['Observations']}',
				Resolution = '{$_POST['Resolution']}',
				Response = '{$_POST['Response']}',
				refUserAtrib = '{$_POST['refUserAtrib']}',
				{$StatusSolve}
				status = '{$_POST['status']}',
				importance = '{$_POST['importance']}',
				priority = '{$_POST['priority']}',
				time_confirm = '{$timeConfirm}'
			WHERE ref = '{$_POST['ref']}'";
	$Save = $GLOBALS['CONN']->db_query($USave);
	$Msg->SAVE_CLIENT = "Altera��es gravadas.";
	} else {
	$Msg->SAVE_CLIENT = "Erro ao salvar altera��es.";
} 
?>
<script charset="utf-8" type="text/javascript" src="../../../Shared/Libraries/Objects/slide.js"></script>
<script charset="utf-8" type="text/javascript" src="../../../Shared/Libraries/JS/calendar.js"></script> 
<table width="100%"  border="0" cellpadding="10">
  <?php if (isset($_GET['action']) && $_GET['action'] == "show" || !isset($_GET['action'])) { ?>
<tr>
    <td>
	<table width="100%"  border="0" cellpadding="10" cellspacing="2">
      <tr>
        <td rowspan="3" valign="top" bgcolor="#F2F2F2">Log
	      </td>
        </tr>
    </table>
	</td>
  </tr>
  <tr>
    <td>
	<?php 
		$QTicket = "SELECT * FROM it_tickets WHERE ref = '{$_GET['TicketID']}'";
		$Ticket = $GLOBALS['CONN']->db_array($QTicket);
		for ($i = 1; $i <= $Ticket[0]; $i++) { 
		?>
	<table width="100%"  border="0" cellpadding="10" cellspacing="2">
	<form action="edit.php?TicketID=<?php echo $Ticket[$i]['ref'];?>" method="post">
	<input type="hidden" name="ref" value="<?php echo $Ticket[$i]['ref'];?>">
	<input type="hidden" name="time_confirm" value="<?php echo $Ticket[$i]['time_confirm'];?>">
      <tr bgcolor="#009999">
        <td colspan="3">Suporte IT  | Resolução Ticket </td>
      </tr>
      <tr>
        <td width="20%" rowspan="3" valign="top" bgcolor="#F2F2F2">
	<table width="100%" border="0" cellpadding="4" cellspacing="1">
      <tr>
        <td colspan="2">Aberto por:<?php echo $_SESSION['UtAD'];?>,<br>
          a: <?php echo date("Y-m-d H:i:s");?></td>
        <td>Responsabilidade:
          <br>
          <select name="refUserAtrib">
            <?php 
				$QDrop = "SELECT * FROM main_users";
				$Drop = $GLOBALS['CONN']->db_array($QDrop);
				for ($t = 1; $t <= $Drop[0]; $t++) { 
                print "<option value=\"{$Drop[$t]['ref']}\"";
				if ($Drop[$t]['ref'] == $Ticket[$i]['refUserAtrib']) { 
					print "selected";
					}
				print ">";
                print $Drop[$t]['name'];
                print "</option>";
				} ?>
          </select>          <br></td>
        <td>&nbsp;</td>
        <td width="30%" rowspan="5"><p>&nbsp;</p>          <p>&nbsp;</p></td>
      </tr>
      <tr>
        <td colspan="2">Cronologia do Evento </td>
        <td colspan="2">Gravidade</td>
        </tr>
      <tr>
        <td>Início da ocorrência<br>
         <?php echo $Ticket[$i]['time_occur'];?>
          </td>
        <td>&nbsp;</td>
        <td>Prioridade<br>
          <select name="priority">
            <?php 
				$QDrop = "SELECT * FROM it_ticket_priority";
				$Drop = $GLOBALS['CONN']->db_array($QDrop);
				for ($t = 1; $t <= $Drop[0]; $t++) { 
                print "<option value=\"{$Drop[$t]['ref']}\"";
				if ($Drop[$t]['ref'] == $Ticket[$i]['priority']) { 
					print "selected";
					}
				print ">";
                print $Drop[$t]['name'];
                print "</option>";
				} ?>
          </select>          <br></td>
        <td>Importancia<br>
          <select name="importance">
            <?php 
				$Qimportance = "SELECT * FROM it_ticket_importance";
				$importance = $GLOBALS['CONN']->db_array($Qimportance);
				for ($t = 1; $t <= $importance[0]; $t++) { 
                print "<option value=\"{$importance[$t]['ref']}\"";
				if ($importance[$t]['ref'] == $Ticket[$i]['importance']) { 
					print "selected";
					}
				print ">";
                print $importance[$t]['name'];
                print "</option>";
				} ?>
          </select></td>
      </tr>
      <tr>
        <td colspan="2" bgcolor="#FFFFFF">Tipificação</td>
        <td width="30%" colspan="2" bgcolor="#FFFFFF">InformaÇ&otilde;es de Fecho </td>
      </tr>
      <tr>
        <td width="25%" bgcolor="#FFFFFF"><p>área<br>
                <select name="Area" onClick="javascript:window.refresh();">
				  <?php 
				$CType = "SELECT * FROM it_ticket_types WHERE level = '0'";
				$Type = $GLOBALS['CONN']->db_array($CType);
				for ($t = 1; $t <= $Type[0]; $t++) { 
                print "<option value=\"{$Type[$t]['ref']}\"";
				if ($Type[$t]['ref'] == $Ticket[$i]['ref_type']) { 
					print "selected";
					}
				print ">";
                print $Type[$t]['name'];
                print "</option>";
				} ?>
                      </select>
          </p>          </td>
        <td width="25%" valign="bottom" bgcolor="#FFFFFF">Sub-área<br>
          <select name="SubArea">
            <?php 
				$CType = "SELECT * FROM it_ticket_types WHERE level = '{$_POST['Area']}'";
				$Type = $GLOBALS['CONN']->db_array($CType);
				for ($t = 1; $t <= $Type[0]; $t++) { 
                print "<option value=\"{$Type[$t]['ref']}\"";
				if ($Type[$t]['ref'] == $Ticket[$i]['ref_type']) { 
					print "selected";
					}
				print ">";
                print $Type[$t]['name'];
                print "</option>";
				} ?>
          </select></td>
        <td width="30%" bgcolor="#FFFFFF">Resolução<br>
          <select name="Resolution">
            <?php 
				$QResolution = "SELECT * FROM it_resolution";
				$Resolution = $GLOBALS['CONN']->db_array($QResolution);
				for ($t = 1; $t <= $Resolution[0]; $t++) { 
                print "<option value=\"{$Resolution[$t]['ref']}\"";
				if ($Resolution[$t]['ref'] == $Ticket[$i]['Resolution']) { 
					print "selected";
					}
				print ">";
                print $Resolution[$t]['name'];
                print "</option>";
				} ?>
          </select></td>
        <td width="25%" bgcolor="#FFFFFF">Estado<br>
          <select name="status">
            <?php 
				$QStatus = "SELECT * FROM it_status";
				$Status = $GLOBALS['CONN']->db_array($QStatus);
				for ($t = 1; $t <= $Status[0]; $t++) { 
                print "<option value=\"{$Status[$t]['ref']}\"";
				if ($Status[$t]['ref'] == $Ticket[$i]['status']) { 
					print "selected";
					}
				print ">";
                print $Status[$t]['name'];
                print "</option>";
				} ?>
          </select></td>
      </tr>
      <tr>
        <td colspan="5"><p>Descrição<br>
            <textarea name="Description" cols="90" rows="6" id="Description" disabled><?php echo $Ticket[$i]['Description'];?></textarea>
            </p>
          <p>
            ObservaÇ&otilde;es<br>
            <textarea name="Observations" cols="90" rows="6" id="textarea"><?php echo $Ticket[$i]['Observations'];?></textarea>
</p>          <p>
            Resposta<br>
            <textarea name="Response" cols="90" rows="6" id="textarea"><?php echo $Ticket[$i]['Response'];?></textarea>
</p>
<p><input name="SaveTicket" type="submit" id="SaveTicket" value="Salvar"></p>
		  </td>
        </tr>
    </table>
	</td>
	  </tr>
	  </form>
    </table>
	<?php } ?>
	</td>
  </tr>
  <?php } ?> 
</table>
<?php print footer(); ?>